/*
 * Copyright © 2012 Nokia Corporation. All rights reserved.
 * Nokia and Nokia Connecting People are registered trademarks of Nokia Corporation.
 * Oracle and Java are trademarks or registered trademarks of Oracle and/or its
 * affiliates. Other product and company names mentioned herein may be trademarks
 * or trade names of their respective owners.
 * See LICENSE.TXT for license information.
 */

package com.nokia.example.gfxsensorsdemo.sensors;

public abstract class AccelerationProvider {

    private AcclerationProviderListener listener;

    /**
     * Callback for subclasses
     * @param ax
     * @param ay
     * @param az 
     */
    protected final void dataReceived(double ax, double ay, double az) {
        if (listener != null) {
            listener.dataReceived(ax, ay, az);
        }
    }

    /**
     * Closes the sensor connection
     */
    public abstract void close();

    public static AccelerationProvider getProvider(AcclerationProviderListener listener) {
        AccelerationProvider provider = null;
        try {
            if (sensorsSupported()) {
                /*Class c = Class.forName("com.nokia.example.gfxsensorsdemo.sensors."
                        + "AccelerationProviderImpl");
                provider = (AccelerationProvider) c.newInstance();*/
            	provider = new AccelerationProviderImpl();
                provider.listener = listener;
            }
        }
        catch (Exception e) {
        }
        return provider;
    }

    /*public interface Listener {

        void dataReceived(double ax, double ay, double az);
    }*/

    public static boolean sensorsSupported() {
        try {
            Class.forName("javax.microedition.sensor.SensorConnection");
            return true;
        }
        catch (Exception e) {
            return false;
        }
    }
}
